package com.movitech.mobile.cz.base.common.util;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

/**
 * 头部获取
 * @author Aibal.He
 *
 */
public class HeadersUtils {

	/**
	 * 根据头部key，获取头部数据
	 * @param httpServletRequest
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static String getHeadByKey(HttpServletRequest httpServletRequest,String headkey) {
		Enumeration enumeration = httpServletRequest.getHeaderNames();
		while (enumeration.hasMoreElements()) {
			String key = (String) enumeration.nextElement();
			String value = httpServletRequest.getHeader(key);
			if (StringUtils.equalsIgnoreCase(key,headkey)) {
				return value.trim();
			}
		}
		return "";
	}
	
	/**
	 * 获取区域类型
	 * 
	 * @param httpServletRequest
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static String getAreaId(HttpServletRequest httpServletRequest) {
		Enumeration enumeration = httpServletRequest.getHeaderNames();
		while (enumeration.hasMoreElements()) {
			String key = (String) enumeration.nextElement();
			String value = httpServletRequest.getHeader(key);
			if (key.equalsIgnoreCase("areaId")) {
				return value.trim();
			}
		}
		return "";
	}
	/**
	 * 获取区域类型
	 * 
	 * @param httpServletRequest
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static String getAreaPId(HttpServletRequest httpServletRequest) {
		Enumeration enumeration = httpServletRequest.getHeaderNames();
		while (enumeration.hasMoreElements()) {
			String key = (String) enumeration.nextElement();
			String value = httpServletRequest.getHeader(key);
			if (key.equalsIgnoreCase("areaPId")) {
				return value.trim();
			}
		}
		return "";
	}
	/**
	 * 获取语言类型
	 * 
	 * @param httpServletRequest
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static String getLanguage(HttpServletRequest httpServletRequest) {
		Enumeration enumeration = httpServletRequest.getHeaderNames();
		while (enumeration.hasMoreElements()) {
			String key = (String) enumeration.nextElement();
			String value = httpServletRequest.getHeader(key);
			if (key.equalsIgnoreCase("language")) {
				return value.trim();
			}
		}
		return "";
	}
}
